home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / SAVEVALS.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  2KB  |  74 lines

  1. /*  SAVEVALS.C
  2.  *  last mod.: 12-SEP-91
  3.  */
  4.  
  5. #include <STDIO.H>
  6. #include <STDLIB.H>
  7. #include <STRING.H>
  8. #include <L_FILE.H>
  9. #include <L_STR.H>
  10.  
  11. /*    structure for saving values in    */
  12. struct save_t
  13.     {
  14.     Uchar id_string[13];     /*  12 id bytes  */
  15.     Uchar x[21];
  16.     int y;
  17.     /*  substitute variables as required  */
  18.     } ;
  19.  
  20. struct save_t save =
  21.     {
  22.     "oneflewovert", "ABC", 123  /* , ...  */
  23.     };
  24. /*    initial values for save variables  */
  25.  
  26. Uchar buffer[4000];
  27.  
  28. void main(int argc, char *argv[])
  29. {
  30. printf("The current values are: %s, %d\n",save.x,save.y);
  31. printf("Enter new string value for x: ");
  32. gets_n(save.x,20);
  33. if ( !*trim(save.x) )
  34.     exit(0);
  35.  
  36. printf("\nEnter new integer value for y: ");
  37. gets_n(buffer,5);
  38. if ( !*trim(buffer) )
  39.     exit(0);
  40.  
  41. save.y = atoi(buffer);
  42.  
  43. switch ( save_values_in_exe(argv[0],&save,sizeof(save),
  44.     save.id_string,buffer,sizeof(buffer)) )
  45.     {
  46.     case 0:
  47.         printf("\nValues saved for next run.\n");
  48.         break;
  49.     case -1:
  50.         printf("save_size <= len_id_string.\n");
  51.         break;
  52.     case -2:
  53.         printf("buff_size < 8*save_size.\n");
  54.         break;
  55.     case -3:
  56.         printf("Cannot find .EXE file.\n");
  57.         break;
  58.     case -4:
  59.         printf("Error when reading .EXE file.\n");
  60.         break;
  61.     case -5:
  62.         printf("Cannot locate save structure in .EXE file.\n");
  63.         break;
  64.     case -6:
  65.         printf("File is not an .EXE file.\n");
  66.         break;
  67.     case -7:
  68.         printf("Cannot write save structure to .EXE file.\n");
  69.         break;
  70.     default:
  71.         printf("Unknown error.\n");
  72.     }
  73. }
  74.